/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.dusty.fs.filesystem.utils;

import java.io.*;

/**
 *
 * @author Dusty
 */
public class FsConfig {
    
    private static final String CONFIG_FILE = "config";
    
    private int blockSize;
    
    private int blockCount;
    
    private String root;
    
    public FsConfig(String root) {
        this.root = root;
        loadDefaultConfig();
    }
    
    public void loadConfig() throws FileNotFoundException, IOException, NumberFormatException {
        File config = new File(root + File.separator + CONFIG_FILE);
        FileReader fr = new FileReader(config);
        BufferedReader reader = new BufferedReader(fr);
        
        try {
            blockSize = Integer.parseInt(reader.readLine().trim());
            blockCount = Integer.parseInt(reader.readLine().trim());
        } finally {
            reader.close();
            fr.close();
        }   
    }
    
    public final void loadDefaultConfig() {
        blockSize = Utils.BLOCK_MIN_SIZE;
        blockCount = Utils.BLOCK_MIN_COUNT;
    }

    public int getBlockCount() {
        return blockCount;
    }

    public int getBlockSize() {
        return blockSize;
    }

    public void setBlockCount(int blockCount) {
        this.blockCount = blockCount;
    }

    public void setBlockSize(int blockSize) {
        this.blockSize = blockSize;
    }
}
